﻿var grid;
var varIncrementer = 0;
var v_TrnContractID = varIncrementer++,
        v_Sr = varIncrementer++,
        v_Action = varIncrementer++,
        v_CompanyName = varIncrementer++,
        v_ClientName = varIncrementer++,
        v_ContractName = varIncrementer++,
        v_ContractNo = varIncrementer++,
        v_PaymentModeName = varIncrementer++,
        v_LastInvoiceNo = varIncrementer++,
        v_LastInvoiceDate = varIncrementer++,
        v_NextPaymentDay = varIncrementer++,
        v_ContractAmount = varIncrementer++,
        v_InvoicedAmt = varIncrementer++,
        v_DueAmount = varIncrementer++;

$(document).ready(function () {
    $('#cboCompany').select2();
    $('#cboClient').select2();
    $('#cboContract').select2();
    $('#cboPaymentMode').select2();

    $('#cboCompany').focus();
});

function fn_GetSearchResult(p_vTrack, p_objResult) {
    if (p_vTrack == "0") {
        callBack('GetSearchResult', 'cboCompany@cboContract@cboClient@cboPaymentMode@txtInvoiceStartDate@txtInvoiceEndDate');
    }
    else {
        document.getElementById("divResult").innerHTML = p_objResult.grdResult;
    }
    return false;
}

function ShowEditDiv(objControl) {
    var varRow = objControl.parentNode.parentNode;
    var varTitle = "Contract Details  # " + varRow.cells[v_ContractNo].innerText;
    $('#divShowDetails').dialog('open');
    $('#divShowDetails').dialog("option", "title", varTitle);
    document.getElementById('lblCompanyName').innerText = varRow.cells[v_CompanyName].innerText;
    document.getElementById('lblClientName').innerText = varRow.cells[v_ClientName].innerText;
    document.getElementById('lblContractName').innerText = varRow.cells[v_ContractName].innerText;
     
    var vAdditionalTrack = "RowID@@" + varRow.cells[v_Sr].innerText + "~~ContractID@@" + varRow.cells[v_TrnContractID].innerText;
    callBack('ViewDetails', '', vAdditionalTrack);
}

function getResponse(returnVal) {
    try {
        hideLoader(returnVal);
        var objResult = $.parseJSON(returnVal);
        if (objResult.SessionTimeOut == "1") {
            window.location.href = 'login.aspx';
        }
        else {
            var varTrack = objResult.Track;
            if (varTrack == "GetSearchResult") {
                fn_GetSearchResult("1", objResult);
            }
            else if (varTrack == "ViewDetails") {
                document.getElementById("divInvoiceDetails").innerHTML = objResult.grdInvoiceDetails;
                document.getElementById("divCollectionDetails").innerHTML = objResult.grdCollectionDetails;
            }
        }
    }
    catch (ex) {
        show_globalMessage('Error', 'error');
    }
}
 